<?php
	require_once ("../../config.php");	

	# Verify what button was clicked.
	$btaction = $_POST["submit_loginfind"];
	
	if ($btaction == "Voltar"){
		header("Location: /itcontrol/com/main/main.php");
	}else{	
		
		# Get data previous inserted
		$id = $_POST["input_id"];
		$name = $_POST["input_name"];
		$lastname = $_POST["input_lastname"];
		$login = $_POST["input_login"];
		$email = $_POST["input_email"];
		
		$fields["id"] = "id";
		$fields["name"] = "name";
		$fields["lastname"] = "lastname";
		$fields["login"] = "login";
		$fields["email"] = "email";
		
		$namefields["id"] = "ID";
		$namefields["name"] = "Nome";
		$namefields["lastname"] = "Sobrenome";
		$namefields["login"] = "Login";
		$namefields["email"] = "Email";
		
		# Check if there is some empty field
		if(!empty($id)){	
			$where["id"] = $fields["id"]. "='" .$id. "'";
		}
		
		if(!empty($name)){
			$where["name"] = $fields["name"]. "='" .$name. "'";
		}
		
		if(!empty($lastname)){
			$where["lastname"] = $fields["lastname"]. "='" .$lastname. "'";
		}
		
		if(!empty($login)){
			$where["login"] = $fields["login"]. "='" .$login. "'";
		}
		
		if(!empty($email)){
			$where["email"] = $fields["email"]. "='" .$email. "'";
		}
		
		$dbconnection = new connectDB();
		
		$query = mysql_query($dbconnection->selectDB("tb_login", "login", "find", $fields, $namefields, $where));
		
		$query = mysql_fetch_array($query);
		
		$values = urlencode(implode(",", $where));
		
		$dbconnection->disconnectDB();
		
		header("Location: /itcontrol/com/main/login/login_list.php?return=" .$values);
		
	}
?>